﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PMS.Logic.BD
{
    public partial class DepartmentPositionAjax : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String methodName = Request["method"];
            Type type = this.GetType();
            MethodInfo method = type.GetMethod(methodName);
            if (method == null) throw new Exception("method is null");
            try
            {

                method.Invoke(this, null);
            }
            catch
            {
                throw;
            }
        }
        #region 部门信息管理
        //获取部门管理信息
        public void GetDepManageList()
        {
            List<SearchCondition> listSearch = new List<SearchCondition>();
            if (Request.Form["searchData"] != null)
            {
                string searchData = Request.Form["searchData"];
                listSearch = ModelTools.GetSearchContions(searchData);
            }
            Expression<Func<BD_DepInfo, bool>> exp = SearchExpression.FindByGroup<BD_DepInfo>(listSearch);
            string OrderId = OperateContext.Sort == null ? "ID" : OperateContext.Sort;
            int count = 0;
            var list = DALSession.Current.BD_DepInfoDAL.GetPagedList(OperateContext.Page, OperateContext.Rows, exp, OrderId, OperateContext.Order);
            count = DALSession.Current.BD_DepInfoDAL.GetCount(exp);
            Response.Write(JsonHelper.toPageJson(list, count));
        }
        //增加部门管理信息
        public void AddDepManageList()
        {
            BD_DepInfo per = new BD_DepInfo();
            ModelTools.Form2EditModel(Request.Form, per);
            per.FillDate = DateTime.Now.ToString("yyyy-MM-dd");
            per.ManClerk = OperateContext.SessBasicInfo.UserInfo.Name;
            DALSession.Current.BD_DepInfoDAL.Add(per);
            DALSession.Current.BD_DepInfoDAL.SaveChanges();
            Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        //编辑部门管理信息
        public void EditDepManageList()
        {
            int Id = Commons.String2Int32(Request.Form["ID"]);
            BD_DepInfo perNew = DALSession.Current.BD_DepInfoDAL.GetListBy(d => d.ID == Id).FirstOrDefault();

            ModelTools.Form2EditModel(Request.Form, perNew);
            perNew.FillDate = DateTime.Now.ToString("yyyy-MM-dd");
            perNew.ManClerk = OperateContext.SessBasicInfo.UserInfo.Name;
            DALSession.Current.BD_DepInfoDAL.ModifyAllModel(perNew);
            DALSession.Current.BD_DepInfoDAL.SaveChanges();
            Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        #endregion


        //获取班组
        public void GetProClass()
        {

            //int count = 0;
            //var list = DALSession.Current.BD_DepInfoDAL.GetPagedList(OperateContext.Page, OperateContext.Rows, d=>d.Disable=="0"&&d.FatherId==4, "ID", OperateContext.Order);
            //count = DALSession.Current.View_BD_DepInfoDAL.GetCount(d => d.Disable == "0" && d.FatherId == 4);
            //Response.Write(JsonHelper.toPageJson(list,count));

        }
        #region
        //获取岗位管理信息
        public void GetPositionList()
        {
            List<SearchCondition> listSearch = new List<SearchCondition>();
            if (Request.Form["searchData"] != null)
            {
                string searchData = Request.Form["searchData"];
                listSearch = ModelTools.GetSearchContions(searchData);
            }

            Expression<Func<View_BD_DepPosInfo, bool>> exp = SearchExpression.FindByGroup<View_BD_DepPosInfo>(listSearch);
            string OrderId = OperateContext.Sort == null ? "ID" : OperateContext.Sort;
            int count = 0;
            var list = DALSession.Current.View_BD_DepPosInfoDAL.GetPagedList(OperateContext.Page, OperateContext.Rows, exp, OrderId, OperateContext.Order);
            count = DALSession.Current.View_BD_DepPosInfoDAL.GetCount(exp);

            Response.Write(JsonHelper.toPageJson(list, count));
        }
        //增加岗位管理信息
        public void AddPositionList()
        {
            //BD_PosInfo per = new BD_PosInfo();
            //ModelTools.Form2EditModel(Request.Form, per);
            //per.FillDate = DateTime.Now.ToString("yyyy-MM-dd");
            //per.ManClerk = OperateContext.SessBasicInfo.UserInfo.Name;
            //DALSession.Current.BD_PosInfoDAL.Add(per);
            //DALSession.Current.BD_PosInfoDAL.SaveChanges();
            //Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        //编辑岗位管理信息
        public void EditPositionList()
        {
            //int Id = Commons.String2Int32(Request.Form["Id"]);
            //BD_PosInfo perNew = DALSession.Current.BD_PosInfoDAL.GetListBy(d => d.ID == Id).FirstOrDefault();
            //ModelTools.Form2EditModel(Request.Form, perNew);
            //perNew.FillDate = DateTime.Now.ToString("yyyy-MM-dd");

            //perNew.ManClerk = OperateContext.SessBasicInfo.UserInfo.Name;
            //DALSession.Current.BD_PosInfoDAL.ModifyAllModel(perNew);
            //DALSession.Current.BD_PosInfoDAL.SaveChanges();
            //Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        #endregion
    }
}